var config = require('../../../utils/config.js');
var util = require('../../../utils/util');
var API_URL = config.API_URL;
var userInfo;
Page({

    /**
     * 页面的初始数据
     */
    data: {
        check: false,
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        userInfo = my.getStorageSync({ key: 'user' }).data;
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        var that = this;
        my.httpRequest({
            url: API_URL.account_status,
            data: {
                user_id: userInfo.userId
            },
            method: 'POST',
            success: function (res) {
                console.log(res)
                that.setData({
                    mobile: res.data.data.mobile == 0 ? false : true,
                    identification: res.data.data.identification == 1 ? true : false,
                    hasPaymentPassword: res.data.data.hasPaymentPassword == 1 ? true : false,
                    tel: res.data.data.bindMobile
                })
            },
            fail: function (res) { },
            complete: function (res) { },
        })
    },
    // 实名认证
    identification: function (e) {
        if (this.data.identification) {
            return
        }
        my.navigateTo({
            url: '/pages/user/certification/certification',
        })
    },
    // 绑定手机号码
    mobile: function (e) {
        if (this.data.mobile) {
            my.navigateTo({
                url: '/pages/user/account/change/change',
            })
        } else {
            my.navigateTo({
                url: '/pages/user/account/bind/bind?name=手机&typ=mobile',
            })
        }
    },
    // 修改登录密码
    password: function () {
        my.navigateTo({
            url: '/pages/user/password/password'
        })
    },
    // 支付密码修改
    check: function () {
        var that = this;
        var tem = this.data.check;
        that.setData({
            check: !tem,
        })
    },
    // 修改支付密码
    editPW: function (e) {
        var that = this;
        my.navigateTo({
            url: '/pages/user/pay/code/code?tag=edit&tel=' + that.data.tel,
        })
    },
    // 设置密码
    setPW: function (e) {
        var tag = e.currentTarget.dataset.tag;
        var that = this;
        if (that.data.identification && that.data.mobile) {
            my.navigateTo({
                url: '/pages/user/pay/code/code?tel=' + that.data.tel + "&tag=" + tag,
            })
        }
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

})